1316번 그룹 단어 체커

Day6 6단계 20231024

(해결 날짜 : 20231026)

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int num = Integer.parseInt(br.readLine());
		Map<Character, Integer> groupData = new HashMap<>();
		int groupNum = num;
		pass: for(int i = 0; i < num; i++) {
			String str = br.readLine();
			for(int j = 0; j < str.length(); j++) {
				if(!groupData.containsKey(str.charAt(j))) {
					groupData.put(str.charAt(j), 1);
				}
				if (j < str.length() - 1) {
					if(str.charAt(j) != str.charAt(j+1)) {
						if (groupData.containsKey(str.charAt(j+1))) {
							groupNum--;
							groupData.clear();
							continue pass;
						}
					}
				}
			}
			groupData.clear();
		}
		System.out.println(groupNum);
		br.close();
	}
}
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int count = 0;
		
		while(n-- > 0) {
			String s = sc.next();
			int len = s.length();
			int[] array = new int[26];
			for(int i = 0; i < len; i++) {
				if(array[s.charAt(i)-97] == 0) {
					while(i+1 < len && s.charAt(i+1) == s.charAt(i)) {i++;}
				}
				else {
					count--;
					break;
				}
				array[s.charAt(i)-97]++;
			}
			count++;
		}
		
		System.out.println(count);

	}
}